package com.lemon.smartsafetynew.ui.fragment.record;

import android.os.Bundle;
import android.view.View;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.record.MetalVo;
import com.lemon.smartsafetynew.entity.me.MeCompanyVo;
import com.lemon.smartsafetynew.net.services.RecordServices;
import com.lemon.smartsafetynew.ui.activity.record.RecordMetalDetailActivity;
import com.lemon.smartsafetynew.ui.adapter.record.MetalInfoAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshAddTitleFragment;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * 冶金信息
 * Created by JiangAn on 2018/5/24.
 */

public class RecordMetalFragment extends BasePullToRefreshAddTitleFragment<MetalVo, List<MetalVo>>
        implements RecyclerTClickListener<MetalVo> {

    private static MeCompanyVo companyVo;

    public static RecordMetalFragment newInstance(MeCompanyVo companyVo) {
        Bundle args = new Bundle();
        RecordMetalFragment fragment = new RecordMetalFragment();
        args.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();

        Bundle bundle = getArguments();
        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_COMPANY_VO)) {
                companyVo = (MeCompanyVo) bundle.getSerializable(KeyConstants.KEY_COMPANY_VO);
            }
        }
    }

    @Override
    protected void initViews() {
        super.initViews();
        llTilte.setVisibility(View.VISIBLE);
        tvTitle.setText(R.string.company_space_count);
    }

    @Override
    public void onPullRefresh() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", companyVo.getCompany_id());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        RecordServices.init().getMetalList(RefreshType.REFRESH, params);
    }

    @Override
    public void onLoadMore() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", companyVo.getCompany_id());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        RecordServices.init().getMetalList(RefreshType.LOAD_MORE, params);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<MetalVo> getLemonAdapter() {
        return new MetalInfoAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_GET_METAL_LIST;
    }

    @Override
    public void onDataList(List<MetalVo> data) {
        if(data != null && data.size() > 0) {
            tvTitleCount.setText("" + data.get(0).getTotalNumber());
        }else{
            tvTitleCount.setText("0");
        }
    }

    @Override
    public void onItemClick(MetalVo data, int position) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
        bundle.putSerializable(KeyConstants.KEY_RECORD_METAL_VO, data);
        UIHelper.showActivity(getmContext(), bundle, RecordMetalDetailActivity.class);
    }
}

